import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';

export const STORE_TOKEN = new InjectionToken<IStore>('AUTH_STORE_TOKEN');

export interface IStore {
  get(key: string): IToken;

  set(key: string, value: IToken, options: any): boolean;

  remove(key: string, options: any);
}

export const SERVICE_TOKEN = new InjectionToken<ITokenService>(
  'AUTH_TOKEN_SERVICE_TOKEN',
);

export interface IToken {
  [key: string]: any;

  token: string;
}

export interface ITokenService {

  /** 获取登录地址 */
  readonly login_url: string;

  /** 登录后跳转地址，未指定时返回 `/` */
  redirect: string;

  set(data: IToken): boolean;

  /**
   * 获取Token，形式包括：
   * - `get()` 获取 Simple Token
   * - `get<JWTTokenModel>(JWTTokenModel)` 获取 JWT Token
   */
  get(type?: any): IToken;

  /**
   * 获取Token，形式包括：
   * - `get()` 获取 Simple Token
   * - `get<JWTTokenModel>(JWTTokenModel)` 获取 JWT Token
   */
  get<T extends IToken>(type?: any): T;

  clear(): void;

  change(): Observable<IToken>;
}
